﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.kiosk {
    import reprise.ui.*;
    import flash.events.*;
    import flash.display.*;
    import reprise.controls.*;
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.views.components.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.models.world.*;

    public class KioskPopupMediator extends AbstractPopupMediator {

        public var world:WorldModel;
        public var userModel:UserModel;
        private var _tabViews:Dictionary;
        private var _openTab:String = "COFFEE_TAB"
        private var _selectedTab:String;
        private var _coinsLabel:Label;
        private var _goodsLabel:Label;

        private static const TAB_ITEMS:String = "tabItems";
        private static const TAB_TOYS:String = "tabToys";
        private static const TAB_COFFEE:String = "tabCoffee";

        public function KioskPopupMediator(){
            this._tabViews = new Dictionary();
            super();
        }
        override public function onRegister():void{
            super.onRegister();
            addContextListener(EventConstants.UPDATE_USER_DATA, this.onUpdateUserData, InfoEvent);
            _popupType = GameConstants.KIOSK_POPUP;
            this._selectedTab = String(this.view.data);
            var _local1:UIComponent = RepriseUtils.addComponent(this.view, "content");
            var _local2:UIComponent = RepriseUtils.addComponent(_local1, "tabNavigationDisplay");
            this.createKioskTabViews(_local1);
            this.createKioskTabNavigation(_local2);
            this.createKioskHeader();
            this.createInventoryDisplay();
        }
        private function createKioskHeader():void{
            addLabel("kioskHeader showcardGothicFont", "room_kiosk", null, this.view);
        }
        private function createInventoryDisplay():void{
            var _local1:int = this.userModel.coins;
            var _local2:int = this.userModel.goods;
            var _local3:UIComponent = RepriseUtils.addComponent(this.view, "inventory");
            this._coinsLabel = this.createInventoryItemDisplay(_local3, _local1, "RewardCoinsThumb");
            this._goodsLabel = this.createInventoryItemDisplay(_local3, _local2, "RewardGoodsThumb");
        }
        private function createInventoryItemDisplay(_arg1:UIComponent, _arg2:int, _arg3:String):Label{
            var target = _arg1;
            var amount = _arg2;
            var asset = _arg3;
            var itemContainer:UIComponent = RepriseUtils.addComponent(target, "item");
            var iconClip:MovieClip = AssetsLibrary.getMovieClip(asset);
            var icon:UIComponent = RepriseUtils.addClipComponent(itemContainer, "itemIcon", iconClip);
            RepriseUtils.validateComponent(icon, function (_arg1:ClipComponent):void{
                Displays.correctScaling(_arg1, _arg1.clip, _arg1.width, _arg1.height, 0, 0);
            });
            var label:Label = RepriseUtils.addLabel(itemContainer, "myriadProFontOutline itemLabel", amount.toString());
            return (label);
        }
        private function createKioskTabViews(_arg1:UIComponent):void{
            var _local2:CoffeeTabView = (RepriseUtils.addComponent(_arg1, "tabView", CoffeeTabView) as CoffeeTabView);
            this._tabViews[TAB_COFFEE] = _local2;
            var _local3:ItemTabView = (RepriseUtils.addComponent(_arg1, "tabView", ItemTabView) as ItemTabView);
            _local3.hide();
            this._tabViews[TAB_ITEMS] = _local3;
            var _local4:ToysTabView = (RepriseUtils.addComponent(_arg1, "tabView", ToysTabView) as ToysTabView);
            _local4.hide();
            this._tabViews[TAB_TOYS] = _local4;
        }
        private function createKioskTabNavigation(_arg1:UIComponent):void{
            var _local2:RadioButtonGroup = this.createTabButton(_arg1, "kiosk_tab_coffee", TAB_COFFEE, (this._selectedTab == GameConstants.COFFEE_TAB)).group();
            _local2.addEventListener(Event.CHANGE, this.tabButtonGroup_change);
            this.createTabButton(_arg1, "kiosk_tab_items", TAB_ITEMS, (this._selectedTab == GameConstants.FOOD_TAB));
            this.createTabButton(_arg1, "kiosk_tab_toys", TAB_TOYS, (this._selectedTab == GameConstants.TOYS_TAB));
        }
        private function tabButtonGroup_change(_arg1:Event):void{
            var _local2:UIComponent;
            var _local3:RadioButtonGroup = RadioButtonGroup(_arg1.target);
            for each (_local2 in this._tabViews) {
                _local2.hide();
            };
            _local2 = this._tabViews[_local3.selectedData()];
            _local2.show();
        }
        private function createTabButton(_arg1:UIComponent, _arg2:String, _arg3:Object, _arg4:Boolean):RadioButton{
            var _local5:RadioButton = RepriseUtils.addRadioButton(_arg1, "tabButton showcardGothicFont", "kiosk_tab_group", language.getTextByKey(_arg2));
            _local5.setData(_arg3);
            _local5.selected = _arg4;
            return (_local5);
        }
        private function onUpdateUserData(_arg1:InfoEvent):void{
            var _local2:Object = _arg1.info.changes;
            if (_local2){
                if (_local2.hasOwnProperty("coins_new")){
                    this._coinsLabel.setLabel(_local2.coins_new);
                };
                if (_local2.hasOwnProperty("goods_new")){
                    this._goodsLabel.setLabel(_local2.goods_new);
                };
            };
        }
        private function get view():KioskPopupView{
            return ((viewComponent as KioskPopupView));
        }

    }
}//package net.wooga.pets.views.popups.kiosk 
